#include <stdio.h>
#include <pci/pci.h>

int main() {
	// 初始化 PCI 访问
	struct pci_access *pacc = pci_alloc();  // 分配 PCI 访问结构体
	pci_init(pacc);                         // 初始化 PCI 库
	pci_scan_bus(pacc);                     // 扫描 PCI 总线

	// 遍历所有设备并打印信息
	struct pci_dev *dev;
	for (dev = pacc->devices; dev; dev = dev->next) {
		pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);  // 填充设备信息

		printf("Device: %04x:%02x:%02x.%d (Vendor=%04x, Device=%04x)\n",
				dev->domain, dev->bus, dev->dev, dev->func,
				dev->vendor_id, dev->device_id);

		printf("  Class: %04x\n", dev->device_class);
		printf("  IRQ: %d\n", dev->irq);
		printf("  Memory Base: 0x%lx\n", (unsigned long)dev->base_addr[0]);

		printf("-------------------------------\n");
	}

	pci_cleanup(pacc);  // 清理 PCI 库
	return 0;
}

